package com.project.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.bean.InventoryManagement.AgentiaBean;
import com.project.bean.InventoryManagement.MoveBean;
import com.project.mapper.IMoveMapper;
import com.project.service.IMoveService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

@Service
@Transactional
public class IMoveServiceImpl extends ServiceImpl<IMoveMapper, MoveBean> implements IMoveService {

    @Resource
    private IMoveMapper mapper;


    @Override
    public IPage<MoveBean> findMove(int pageNo, int pageSize, LocalDate startDate, LocalDate endDate, String moveClass) {
        Page<MoveBean> page = new Page<>(pageNo,pageSize);

        QueryWrapper wrapper = new QueryWrapper<>();

        if (moveClass != null){
            wrapper.like("move_class",moveClass);
        }
        if (startDate != null){
            wrapper.gt("move_day",startDate);
        }
        if (endDate != null){
            wrapper.lt("move_day",endDate);
        }



        return this.baseMapper.selectPage(page,wrapper);

    }

    @Override
    public MoveBean findMoveById(int moveId) {
        return mapper.findMoveById(moveId);
    }

    @Override
    public MoveBean findMoveMsg(String moveClass) {

        return mapper.findMoveMsg(moveClass);

    }


    //-----------------------------------------------------------------------------
    @Override
    public void addMove(MoveBean moveBean) {
        this.save(moveBean);
    }

    @Override
    public void addAgentia(int moveId, int agentiaId,int detailsNum) {
        mapper.addAgentia(moveId,agentiaId,detailsNum);
    }

    @Override
    public void delAgentia(int moveId, int agentiaId) {

        mapper.delAgentia(moveId,agentiaId);

    }

    @Override
    public void updateNum(int moveId,int agentiaId,int newNum) {

        mapper.updateNum(moveId,agentiaId,newNum);

    }


}
